package com.fbt.transfer.app.driver.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;

import com.fbt.transfer.app.driver.R;
import com.fbt.transfer.app.driver.model.index.IndexStats;

/**
 * 首页统计信息视图组件
 */
public class IndexStatsView extends CardView {

    private TextView tvTodayIncome;
    private TextView tvTodayFinishedCount;
    private TextView tvTodayCount;
    private TextView tvWaitCount;

    public IndexStatsView(@NonNull Context context) {
        super(context);
        init(context);
    }

    public IndexStatsView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public IndexStatsView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.view_index_stats, this, true);
        findViews();
    }

    private void findViews() {
        tvTodayIncome = findViewById(R.id.tv_today_income);
        tvTodayFinishedCount = findViewById(R.id.tv_today_finished_count);
        tvTodayCount = findViewById(R.id.tv_today_count);
        tvWaitCount = findViewById(R.id.tv_wait_count);
    }

    /**
     * 更新统计信息
     * @param stats 统计数据
     */
    public void updateStats(IndexStats stats) {
        if (stats == null) {
            return;
        }
        
        // 设置今日收入
        tvTodayIncome.setText(String.format("¥%s", stats.getTodayIncome().toPlainString()));
        
        // 设置今日完单数
        tvTodayFinishedCount.setText(String.valueOf(stats.getTodayFinishedCount()));
        
        // 设置今日任务数
        tvTodayCount.setText(String.valueOf(stats.getTodayCount()));
        
        // 设置待办订单数
        tvWaitCount.setText(String.valueOf(stats.getWaitCount()));
    }
}